package com.maya.controller;

import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.maya.model.Log;
import com.maya.model.User;
import com.maya.service.LogService;
import com.maya.service.UserService;




@Controller

public class ViewUserController {
	
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private LogService logService;
	
	@RequestMapping("/viewuser")
    public String viewuser(String userid,Model model){
    	 	
                               
            User  user = userService.get(new ObjectId(userid));
            if(null != user) {
                
                List<Log> logs = logService.getByOwnerId(user.getId());
                
                
                for(Log l : logs) {
                    System.out.println(l.getTitle());
                    System.out.println(l.getTargetId());
                }
                
                System.out.println(user.getName());
                model.addAttribute("logs", logs);
                model.addAttribute("vieweduser", user);
                
                return "user";
               
                
            }
            else {
                
            	return "notfound";
            }
            

    }
    
    

}
